#include<iostream>
#include<cstdio>
using namespace std;
long long MOD = (long long)998244353;

long long modpow(long long a, long long e) {
    long long r = 1 % MOD;
    a %= MOD;
    while (e > 0) {
        if (e & 1) r = (r * a) % MOD;
        a = (a * a) % MOD;
        e >>= 1;
    }
    return r;
}

int main() {
    int T = 0;
    cin >> T;
    while(T--) {
        int n = 0;
        cin >> n;
        long long *p = new long long[n+2];
        for(int i = 0; i<=n ; i++) {
            cin >> p[i];
        }
        
        char *left_bigger = new char[n+2];
        // 左侧更大的数记录下来
        long long max = -1;
        for(int i = 1; i<=n ; i++) {
            left_bigger[i] = (max > p[i]) ? 1:0;
            if(p[i] > max)
                max = p[i];
        }
        
        char *right_smaller = new char[n+2];
        // 同理
        long long min = (long long)99824435399999;
        for(int i = n; i>=1; i--) {
            right_smaller[i] = (min < p[i]) ? 1:0;
            if(p[i] < min)
                min = p[i];
        }
        // k1表示不参与逆序对的数量
        // k2则是参与逆序对中的数
        int k1=0, k2 = 0;
        for(int i = 1; i<=n; i++) {
            if(left_bigger[i] || right_smaller[i])
                k2++;
            else
                k1++;
        }
        
        long long res = modpow(2, k1);
        if(k2==0) {
            res = (res-1+MOD)%MOD;
        }
        cout<<res<<endl;
    }
    return 0;
}